package com.hxzy.service.impl;

import com.hxzy.util.MybatisUtil;
import com.hxzy.dto.BusinessResourceDTO;
import com.hxzy.entity.BusinessResourceSupplier;
import com.hxzy.mapper.BusinessResourceSupplierMapper;
import com.hxzy.service.BusinessResourceSupplierService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Description:
 * @Author: YaoHaiLong
 * @Date: 2022/3/8 17:20
 */
public class BusinessResourceSupplierServiceIpmi implements BusinessResourceSupplierService {
    @Override
    public int insert(BusinessResourceSupplier businessResourceSupplier) {
        int  count=0;
      try(SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()) {
          BusinessResourceSupplierMapper mapper = sqlSession.getMapper(BusinessResourceSupplierMapper.class);
       count = mapper.insert(businessResourceSupplier);
       sqlSession.commit();
      }
      return count;
    }

    @Override
    public List<BusinessResourceSupplier> search(BusinessResourceDTO businessResourceDTO) {
        List<BusinessResourceSupplier>list=null;
        try(SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            BusinessResourceSupplierMapper mapper = sqlSession.getMapper(BusinessResourceSupplierMapper.class);
          list= mapper.search(businessResourceDTO);

        }
        return list;

    }

    @Override
    public int delete(String integer) {
        int  count=0;
        try(SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()) {
            BusinessResourceSupplierMapper mapper = sqlSession.getMapper(BusinessResourceSupplierMapper.class);
            count = mapper.delete(integer);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public int update(BusinessResourceSupplier businessResourceSupplierService) {
        int count=0;
       try(SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
           BusinessResourceSupplierMapper sqlSessionMapper = sqlSession.getMapper(BusinessResourceSupplierMapper.class);
           count=  sqlSessionMapper.update(businessResourceSupplierService);
           sqlSession.commit();
       }
       return count;
    }

    @Override
    public BusinessResourceSupplier searchByName(String name) {
        BusinessResourceSupplier businessResourceSupplier=null;
        try (SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            BusinessResourceSupplierMapper mapper = sqlSession.getMapper(BusinessResourceSupplierMapper.class);
            businessResourceSupplier = mapper.searchByName(name);
        }
        return businessResourceSupplier;
    }
}
